/**
 * 表单自定义控制器
 */
app.controller('btnCtrl', ['$scope', '$http', BtnController]);
function BtnController($scope, $http) {
	$scope.bindBtn = function(event) {
		switch(event){
			case 'event-to-add': // 新增
			{

				$scope.subGrid.sonlist.push({
					id : null,
					code : $scope.valueMap['code'],
					sellerSku : '',
					asin : '',
					fnSku : '',
					isSign : '否',
					signCode : '',
					sellerId : '',
					shopName : '',
					marketplaceName : '',
					countIsShow : 1,
				});
				break;
			}
			case 'event-to-del': // 删除
			{

				var datas = [];
				for (var i = 0; i < $scope.subGrid.sonlist.length; i++) {
					var data = $scope.subGrid.sonlist[i];
					if(data['ys_form_sonlist_checkbox']) {
						datas.push(data);
					}
				}

				if (datas.length == 0) {
					layer.alert('尚未选中数据');
				} else {

					layer.confirm('确定要删除SKU信息吗？', { icon: 3 }, function() {
						layer.msg('处理中', { icon: 16, shade: 0.01 });
						var ids = '';
						for(var i=0;i<datas.length;i++){
							if(ids==''){
								ids = datas[i].id;
							}else {
								ids = ids + ',' +datas[i].id;
							}
						}
						$http.post('/api/inter/tpAmazonShopProduct/delByIds', {}, {params: {ids: ids}})
							.success(function (res) {
								layer.closeAll();
								layer.msg(res.msg);
								var datasByNew = [];
								for (var i = 0; i < $scope.subGrid.sonlist.length; i++) {
									var data = $scope.subGrid.sonlist[i];
									if(!data['ys_form_sonlist_checkbox']) {
										datasByNew.push(data);
									}
								}
								$scope.subGrid.sonlist = datasByNew;
							})
							.error(function(result){
								layer.closeAll();
								layer.msg("删除失败，请稍后再试！", { icon: 2 });
							});

					}, function() {
					});

				}
				break;
			}
		};
	}

}



